package com.graduation.roombooking.controller.applet;

import com.graduation.roombooking.service.ICompanyService;
import com.graduation.roombooking.service.UserService;
import com.graduation.roombooking.vo.AppletCompanyVO;
import com.graduation.roombooking.vo.RespBean;
import com.graduation.roombooking.vo.RespBeanEnum;
import com.graduation.roombooking.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:CaiShuangLian
 * @FileName:
 * @Date:Created in  2022/5/10 16:05
 * @Version:
 * @Description:TODO
 */

@Api(tags = "Applet——部门模块")
@RestController
@RequestMapping("/applet/company")
public class AppletCompanyController {
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private UserService userService;

    @ApiOperation("部门列表")
    @ResponseBody
    @PostMapping("/list")
    public RespBean getCompanyList(@RequestBody AppletCompanyVO appletCompanyVO, HttpServletRequest request, HttpServletResponse response){
        String ticket=appletCompanyVO.getTicket();
        if(ticket!=null && !ticket.isEmpty()){
            //根据cookie获取用户信息
            UserVo userVo=userService.getUserByCookie(ticket,request,response);
            if(userVo!=null ){
                return companyService.getAppletCompanyList(appletCompanyVO);

            }
        }
        return RespBean.error(RespBeanEnum.ILLEGAL_OPERATION);
    }
}
